<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <p id="p">old</p>
    <script>
      //.cloneNode方法，node.cloneNode(deep);是否采用深度克隆，如果为true则该节点的后代都会被拷贝，false只拷贝节点本声
      for (var i = 0; i < 3; i++) {
        var p = document.createElement('p')
        p.innerHTML = i
        document.body.appendChild(p)
      }
      /*
       *使用cloneNode进行优化
       */
      var existP = document.getElementById('p')
      for (var i = 0; i < 3; i++) {
        var newP = existP.cloneNode(false)
        newP.innerHTML = i
        document.body.appendChild(newP)
      }
    </script>
  </body>
</html>
